<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.lang.Math" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.atg.com/taglibs/json" prefix="json" %>
<%@ include file="../../Include/Config.jsp"%>
<html>
  <head>
    <title>Web Ram Program</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link href="ram/style.css" rel="stylesheet" type="text/css">
    <style type="text/css">
      #progress {
        display:none;
        position:absolute;
        left:0px;
        top:0px;
        width:1251px;
        height:100%;
        background-color:#f4f4f4;
        opacity:0.7;
        filter:alpha(opacity=70);
        z-index:2;
      }
      #progress span{
        position:absolute;
        left:50%;
        top:50%;
        z-index:1;
      }
      
      #progressSpan {
        opacity:1.0;
        filter:alpha(opacity=100);
      }
      
      #flashContent {
        z-index:3;
      }
      
    </style>
    <script type="text/javascript" src="flex-bin/swfobject.js"></script>
    <script type="text/javascript" src="js/jquery-1.7.1.js"></script>
    <script type="text/javascript" src="js/json.js"></script>
    <script type="text/javascript">
        // For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. 
        var swfVersionStr = "10.2.0";
        // To use express install, set to playerProductInstall.swf, otherwise the empty string. 
        var xiSwfUrlStr = "flex-bin/playerProductInstall.swf";
        var flashvars = {};
        flashvars.sessionID = "${sessionScope.sessionGetId}";
        var params = {};
        params.quality = "high";
        params.bgcolor = "#ffffff";
        params.allowscriptaccess = "sameDomain";
        params.allowfullscreen = "true";
        params.wmode = "opaque";
        var attributes = {};
        attributes.id = "ResultGraph";
        attributes.name = "ResultGraph";
        attributes.align = "middle";
        swfobject.embedSWF(
            "flex-bin/ResultGraph.swf", "flashContent", 
            "778", "205", 
            swfVersionStr, xiSwfUrlStr, 
            flashvars, params, attributes);
        // JavaScript enabled so display the flashContent div in case it is not replaced with a swf object.
        swfobject.createCSS("#flashContent", "display:block;text-align:left;");
    </script>
    <script type="text/javascript">
     $(function(){
          $("#reportImg").css("cursor","pointer").click(function(){
             var f = document.repForm;           
                open ("","NewWindow","left=0, top=0, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=1200, height=950");
                f.target = "NewWindow";
                f.action = "report.do";
                f.submit();               
          });
          
          $("input[type=submit]").click(function(){
              $("#progress").show();
          });
          
      });
          
     function noEvent() {
         if (event.keyCode == 116) {
        	 if(confirm("시뮬레이션을 재실행합니다. \n 다시 하시겠습니까?")){
        		 $("input[type=submit]").click().change();
        	 }else{
        		 event.keyCode = 2;
        		 return false;
        	 }
         }
         else if(event.ctrlKey && (event.keyCode==78 || event.keyCode == 82))
         {
        	 if(confirm("시뮬레이션을 재실행합니다. \n 다시 하시겠습니까?")){
        		 $("input[type=submit]").click().change();
        	 }else{
        		 event.keyCode = 2;
        		 return false;
        	 }
         }
     }
     document.onkeydown = noEvent;    
    </script>
    <%-- --%>
    <logic:notEmpty name="simulationArr">
    <script type="text/javascript">
    /*start JSON for Equip*/
    var equip = <json:object>
                  <logic:iterate id="fig" name="figList" indexId="idx">
                    <json:array name="figRandomNum${fig.figUid}">
                      <logic:iterate id="inFig" name="fig" property="figInform">
                        <logic:equal value="${fig.figUid}" property="figUid" name="inFig">
                          <json:property>${inFig.randomNum}</json:property>
                        </logic:equal>
                      </logic:iterate>
                    </json:array>
                    <json:array name="figHarzard${fig.figUid}">
                      <logic:iterate id="inFig" name="fig" property="figInform">
                        <logic:equal value="${fig.figUid}" property="figUid" name="inFig">
                          <json:property>${inFig.hazardRate}</json:property>
                        </logic:equal>
                      </logic:iterate>
                    </json:array>                         
                  </logic:iterate>
                </json:object>

    //You(Flex manager:Heo Soon Yeol Team Manager) must call this function then you would be able to change MTTF, HarzardRate, Random Fields on list
    //But this function will be shown after simulation then you would be calling
    //I have to write it down in English because broke character on your Mac^^;;
    function setEquipProp(num){
    	//num = 0;
    	<logic:iterate id="fig" name="figList" >
    	  $("#figRandomNum${fig.figUid}").empty();
    	  $("#figHarzard${fig.figUid}").empty();
    	  $("#figRandomNum${fig.figUid}").append(equip.figRandomNum${fig.figUid}[num]);
    	  $("#figHarzard${fig.figUid}").append(equip.figHarzard${fig.figUid}[num]);
    	</logic:iterate>
    }
    /*end JSON for Equip*/
    </script>
    </logic:notEmpty>
     <%----%>
  </head>
  <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <div id="progress">
      <span id="progressSpan">
        <img alt="progress" src="img/ajax-loader.gif"/>
        시뮬레이션 중입니다.
      </span>
    </div>
    <%--
    <logic:notEmpty name="simulationArr">
    
    <json:object>
      <logic:iterate id="fig" name="figList" indexId="idx">
        <json:array name="figRandomNum${fig.figUid}">
          <logic:iterate id="inFig" name="fig" property="figInform">
            <logic:equal value="${fig.figUid}" property="figUid" name="inFig">
              <json:property>${inFig.randomNum}</json:property>
            </logic:equal>
          </logic:iterate>
        </json:array>
        <json:array name="figHarzard${fig.figUid}">
          <logic:iterate id="inFig" name="fig" property="figInform">
            <logic:equal value="${fig.figUid}" property="figUid" name="inFig">
              <json:property>${inFig.hazardRate}</json:property>
            </logic:equal>
          </logic:iterate>
        </json:array>                         
      </logic:iterate>
    </json:object>
    
    </logic:notEmpty>
     --%>
     <form name="repForm" method="post">
          <input type="hidden" name="method" value="list" />
          <input type="hidden" name="proId" value="${sessionScope.unitIDInSession}" />
          <input type="hidden" name="proIterNum" value="${simBaseForm.proIterNum}" />
          <input type="hidden" name="proStartTime" value="${simBaseForm.proStartTime}" />
          <input type="hidden" name="proLifeTime" value="${simBaseForm.proLifeTime}" />
          <input type="hidden" name="proTd" value="${simBaseForm.proTd}" />
          <logic:notEmpty name="simulationArr">
          <logic:iterate id="list" name="simulationArr" indexId="count">
            <logic:iterate id="ts" name="list" property="timeOfSimulation">
              <input type="hidden" name="timeOfSimulation" value="${ts}" />
            </logic:iterate>
            <html:hidden name="list" property="repairTime"/>
            <html:hidden name="list" property="availabilityValue"/>
          </logic:iterate>
          </logic:notEmpty>
     </form>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="100%" style="border:0px solid #ccc">
          <!----- header ----------->
          <jsp:include page="../../Include/Header.jsp"></jsp:include>
          <!--  a id="reportImg" --><!--  a href="javascript:report_sel();" -->
          
          <!----- header end ----------->
        </td>
      </tr>
      <tr>
        <td>
          <div align="left">
            <table width="1251" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="490" valign="top">
                <!--  -->
                  <html:form action="project-submit.do?method=runSimulator" method="post">
                  <html:hidden property="proUid" />
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="30"><font color="ff3300"><b><img src="ram/images/setting.gif"></b></font></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td  bgcolor="#DDDDDD">
                        <table width="100%" border="0" cellspacing="1" cellpadding="5">
                          <tr>
                            <td width="221" align="center" bgcolor="#f4f4f4"><strong>Iteration</strong></td>
                            <td align="center" bgcolor="white" width="246">
                              <p align="left">
                                <html:text property="proIterNum" name="simBaseForm" />times
                              </p>
                            </td>
                          </tr>
                          <tr align="center">
                            <td  bgcolor="#f4f4f4" width="221">
                              <p><b>Setting time</b></p>
                            </td>
                            <td align="left" bgcolor="#FFFFFF" width="246">
                              <p align="left">
                                <html:text property="proStartTime" name="simBaseForm" />years
                              </p>
                            </td>
                          </tr>
                          <tr align="center">
                            <td  bgcolor="#f4f4f4" width="221">
                              <p><b>Life Time</b></p>
                            </td>
                            <td align="left" bgcolor="#FFFFFF" width="246">
                              <p align="left">
                                <html:text property="proLifeTime" name="simBaseForm" />years
                              </p>
                            </td>
                          </tr>
                          <tr align="center">
                            <td  bgcolor="#f4f4f4" width="221">
                              <p><b>of time division/year</b></p>
                            </td>
                            <td align="left" bgcolor="#FFFFFF" width="246">
                              <p align="left">
                                <html:text property="proTd" name="simBaseForm" />times
                              </p>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                  <p align="center">
                    &nbsp;
                    <input type="submit" value="run">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="reportImg" value="report"><!-- span id="reportImg" ><b><font color='red'>report 바로가기</font></b></span -->
                  </p>
                  </html:form>
                </td>
                <td width="20">&nbsp;</td>
                <td width="778" valign="top">
                
                  <table width="100%" style="border:0px solid #ccc;">
                    <tr>
                      <td width="450" height="23"><font color="ff3300"><b><img src="ram/images/result.gif"></b></font></td>
                      <td width="328" height="23"><font color="ff3300"><b><img src="ram/images/graph.gif"></b></font></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>                    
                  </table>

                    <!-- SWFObject's dynamic embed method replaces this alternative HTML content with Flash content when enough 
                         JavaScript and Flash plug-in support is available. The div is initially hidden so that it doesn't show
                         when JavaScript is disabled.
                    -->
                    <div id="flashContent">
                        <p>
                            To view this page ensure that Adobe Flash Player version 
                            10.2.0 or greater is installed. 
                        </p>
                        <script type="text/javascript"> 
                            var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://"); 
                            document.write("<a href='http://www.adobe.com/go/getflashplayer'><img src='" 
                                            + pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>" ); 
                        </script> 
                    </div>
                    <noscript>
                        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="778" height="205" id="ResultGraph">
                            <param name="movie" value="flex-bin/ResultGraph.swf" />
                            <param name="quality" value="high" />
                            <param name="bgcolor" value="#ffffff" />
                            <param name="allowScriptAccess" value="sameDomain" />
                            <param name="allowFullScreen" value="true" />
                            <!--[if !IE]>-->
                            <object type="application/x-shockwave-flash" data="flex-bin/ResultGraph.swf" width="778" height="205">
                                <param name="quality" value="high" />
                                <param name="bgcolor" value="#ffffff" />
                                <param name="allowScriptAccess" value="sameDomain" />
                                <param name="allowFullScreen" value="true" />
                            <!--<![endif]-->
                            <!--[if gte IE 6]>-->
                                <p> 
                                    Either scripts and active content are not permitted to run or Adobe Flash Player version
                                    10.2.0 or greater is not installed.
                                </p>
                            <!--<![endif]-->
                                <a href="http://www.adobe.com/go/getflashplayer">
                                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" />
                                </a>
                            <!--[if !IE]>-->
                            </object>
                            <!--<![endif]-->
                        </object>
                    </noscript>                    
                  </td>
                </tr>
                <tr>
                  <td width="1251" valign="top" colspan="5">&nbsp;</td>
                </tr>
              </table>
              <!---------- 수치값 들어가기 시작 ------------>
              <table width="1251" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td  bgcolor="#DDDDDD">
                    <table width="1251" border="0" cellspacing="1" cellpadding="5">
                      <tr>
                        <td width="40" align="center" bgcolor="#f4f4f4"><strong><b>no</b></strong></td>
                        <td align="center" bgcolor="#f4f4f4" width="100"><p><strong><b>SUBSYSTEM</b></strong></p></td>
                        <td width="150" align="center" bgcolor="#F4F4F4"><b>Equipment</b></td>
                        <td width="74" align="center" bgcolor="#F4F4F4"><b>Tag ID</b></td>
                        <td width="47" align="center" bgcolor="#F4F4F4"><b>Distribution</b></td>
                        <td width="47" align="center" bgcolor="#F4F4F4"><b>Failure Mode</b></td>
                        <td width="47" align="center" bgcolor="#F4F4F4"><b>Failure Time</b></td>
                        <td width="83" align="center" bgcolor="#F4F4F4"><b>Impact of Failure</b></td>
                        <td width="47" align="center" bgcolor="#F4F4F4"><b>MTTR(hours)</b></td>
                        <td width="83" align="center" bgcolor="#F4F4F4"><b>Impact of Repair</b></td>
                        <td width="47" align="center" bgcolor="#F4F4F4"><b>Hazard Rate</b></td>
                        <td width="47" align="center" bgcolor="#F4F4F4"><b>Random Num</b></td>
                      </tr>
                      <logic:iterate id="list" name="figList" indexId="count">
                        <tr align="center">
                          <td bgcolor="#FFFFFF">${count+1}</td>
                          <td align="left" bgcolor="#FFFFFF">${list.figSubsystem}</td>
                          <td width="184" align="left" bgcolor="white">${list.figMoName}</td>
                          <td width="53" align="left" bgcolor="white">${list.figTagid}</td>
                          <td width="53" align="left" bgcolor="white">
                            <logic:equal name="list" property="figDistribution" value="1">
                              Exponential
                            </logic:equal>
                            <logic:equal name="list" property="figDistribution" value="2">
                              Normal
                            </logic:equal>
                            <logic:equal name="list" property="figDistribution" value="3">
                              Rectangular
                            </logic:equal>
                            <logic:equal name="list" property="figDistribution" value="4">
                              Triangular
                            </logic:equal>
                            <logic:equal name="list" property="figDistribution" value="5">
                              Weibull(No Delay)
                            </logic:equal>
                            <logic:equal name="list" property="figDistribution" value="6">
                              Weibull(Time Delay)
                            </logic:equal>
                          </td>
                          <td width="53" align="left" bgcolor="white">${list.figFailMode}</td>
                          <!--  td width="53" align="left" bgcolor="white">${list.figFailureState}</td -->
                          <td width="53" align="left" bgcolor="white">${list.figFailureTime}</td>
                          <td width="53" align="left" bgcolor="white">${list.figImpFailure*100}%</td>
                          <td width="53" align="left" bgcolor="white">${list.figMttr}</td>
                          <td width="53" align="left" bgcolor="white">${list.figImpRepair*100}%</td>
                          <logic:empty name="simulationArr">
                            <td width="53" align="left" bgcolor="white"></td>
                            <td width="53" align="left" bgcolor="white"></td>
                          </logic:empty>
                          <logic:notEmpty name="simulationArr">
                            <td width="53" align="left" bgcolor="white"><span id="figHarzard${list.figUid}"></span></td>
                            <td width="53" align="left" bgcolor="white"><span id="figRandomNum${list.figUid}"></span></td>                            
                          </logic:notEmpty>
                        </tr>                      
                      </logic:iterate>
                    </table>
                  </td>
                </tr>
              </table>
              <!--------- 수치값 들어가기 끝 ------------>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
            </div>
            <p align="center">&nbsp;</p>
          </td>
        </tr>
        <tr>
          <td align="center">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td align="center" bgcolor="d6d6d6"><!---<img src="../images/copy.jpg" width="990" height="30">--->
                  Copyright 2011. Korea Institute of Construction Technology
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <iframe name="hiddenFrame" width="0" height="0"></iframe>
      <!------- 시작 부분 시작 ----->
    </body>
  </html>